﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FreeProperty.Views.Shared;
using FreeProperty.Data;
using System.Data.SqlTypes;

namespace FreeProperty.Views.User
{
    public partial class UserLogin : SiteBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetUI();
            }
            else
            {
                lblError.Text = "";
                switch (hdnMode.Value.ToUpper())
                {
                    case "VALIDATELOGIN":
                        ValidateUser();
                        break;
                    
                }
            }
        }

        private void ValidateUser()
        {
            UserInfo oUserInfo = new UserInfo();
            oUserInfo.EmailID = tbEmailId.Value.Trim();
            oUserInfo.Password = tbPassword.Value.Trim();
            UserInfo oLoggedInUserInfo =  oUserInfo.ValidateLogin();
            if (oUserInfo.ID.IsNull)
            {
                lblError.Text = oLoggedInUserInfo.LoginError;
            }
            else
            {
                
                Session[FreePropertyConstants.SESSION_ACTIVE_USER] = oUserInfo;
                Response.Write("<script>ShowLogout(true);</script>");
                if(null == Session[FreePropertyConstants.SESSION_LOGIN_URL])
                {
                    lblError.Text = "Login Successfull.";
                }
                else
                {
                    Server.Transfer(Session[FreePropertyConstants.SESSION_LOGIN_URL].ToString());
                }
            }
        }

        private void SetUI()
        {
            
        }
    }
}
        